#include<stdio.h>
#include<string.h>
int main()
{
	char a[12];
	int i;
	while(scanf("%s",a),strcmp(a,"0")!=0)
	{
		 int k=0,sum=0;
		 for(i=0;i<11;i++)
		 {
		 	sum+=a[i]-'0'; 
		 }
	    while(sum>=10)
		{
			int s=sum;
			sum=0;
			while(s>0)
			{
				sum+=s%10;
				s/=10;
			}
		}
		printf("%d\n",sum);
	}
	return 0;
} 
